package com.example.wlzz.controller.admin;
import com.example.wlzz.entity.admin.Permission;
import com.example.wlzz.entity.admin.Role;
import com.example.wlzz.repository.PermissionRepository;
import com.example.wlzz.repository.RoleRepository;
import com.example.wlzz.repository.mapper.admin.RoleMapper;
import com.example.wlzz.service.UserService;
import com.example.wlzz.service.serviceImpl.UserServiceImpl;
import com.example.wlzz.utils.ResultVOUtil;
import com.example.wlzz.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/backstage")
@ApiIgnore
public class RoleController {
    @Autowired
    private RoleRepository roleRepository;
    @Autowired
    private PermissionRepository permissionRepository;
    @Autowired
    private RoleMapper roleMapper;


    @PostMapping("/getAllRole")
    @ResponseBody
    public ResultVO getAllRole() {
        List<Role>  roleList = roleRepository.findAll();
        return ResultVOUtil.success(roleList);
    }

    @PostMapping("/getAllPermission")
    @ResponseBody
    public ResultVO getAllPermission() {
        List<Permission>  permissionList = permissionRepository.findAll();
        return ResultVOUtil.success(permissionList);
    }
    @PostMapping("/findPermissionByRoleId")
    @ResponseBody
    public ResultVO findPermissionByRoleId(@RequestParam("role_id")int  role_id) {
       return ResultVOUtil.success(roleMapper.findPermissionByRoleId(role_id));
    }
}
